//
//  TestPlugin.m
//  BSLPlugin
//
//  Created by Fanty on 15/8/15.
//  Copyright (c) 2015年 Fanty. All rights reserved.
//

#import "TTVoicePlugin.h"
#import <AVFoundation/AVFoundation.h>
@implementation TTVoicePlugin
{
    AVSpeechSynthesizer    *_speech ;
    AVSpeechSynthesisVoice *_voice;
}


-(void)showViewController:(CDVInvokedUrlCommand*)command{
    
    if([command.arguments count]<1){
        UIAlertView* alertView=[[UIAlertView alloc] initWithTitle:@"请输入你要转化的文本：[参数1]" message:nil delegate:nil cancelButtonTitle:@"confirm" otherButtonTitles:nil, nil];
        [alertView show];
        return;
    }
    NSString *VoiceStr =[command.arguments objectAtIndex:0];
 
    AVSpeechUtterance *utterance = [[AVSpeechUtterance alloc]initWithString:VoiceStr];
    utterance.voice = _voice;
    utterance.rate = 0.4;
    [_speech speakUtterance:utterance];
    
    CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
    [self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
   
}

-(void)pluginInitialize{
    _speech = [[AVSpeechSynthesizer alloc]init];
    _voice = [AVSpeechSynthesisVoice voiceWithLanguage:@"zh-US"];
    NSLog(@"项目初始运行时所执行的代码");
}



@end




